package tree.domain;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import tree.comparator.NodeASCComparator;

public class Node {

	private String id;
	private String name;
	private String pid;
	private Integer sort;
	private List<Node> children = new ArrayList<Node>();

	public Node() {
	}

	public Node(String id, String name, String pid, Integer sort) {
		this.id = id;
		this.name = name;
		this.pid = pid;
		this.sort = sort;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPid() {
		return pid;
	}

	public void setPid(String pid) {
		this.pid = pid;
	}

	public List<Node> getChildren() {
		return children;
	}

	public void setChildren(List<Node> children) {
		this.children = children;
	}

	public void addChild(Node child) {
		this.children.add(child);
	}

	public Integer getSort() {
		return sort;
	}

	public void setSort(Integer sort) {
		this.sort = sort;
	}

	public void sortChildren() {
		if (this.children != null && !this.children.isEmpty()) {
			Collections.sort(this.children, new NodeASCComparator());
			for (Node child : this.children) {
				child.sortChildren();
			}
		}
	}

}
